package com.dabaozhan.modules.wx_app.service.impl;

import com.dabaozhan.common.entity.Query;
import com.dabaozhan.common.utils.OmsPage;
import com.dabaozhan.common.utils.Utils;
import com.dabaozhan.modules.wx_app.dao.AccountMapper;
import com.dabaozhan.modules.wx_app.entity.AccountEntity;
import com.dabaozhan.modules.wx_app.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author houzhong
 * @date 2018-12-29 11:38
 */
@Service("accountService")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public int saveSiteAccount(AccountEntity v) {
        if (v.getId() == null) {
            v.setId(Utils.id().toString());
        }
        return accountMapper.save(v);
    }

    @Override
    public int updateSiteAccount(AccountEntity v) {

        return accountMapper.update(v);
    }

    @Override
    public int findByAccountCount(Map<String, Object> params) {
        Query query = new Query(params);
        return accountMapper.findByAccountCount(query);
    }

    @Override
    public OmsPage<AccountEntity> findByAccount(Map<String, Object> params) {
        Query query = new Query(params);

        OmsPage<AccountEntity> pages = new OmsPage<AccountEntity>();
        pages.setTotal(accountMapper.findByAccountCount(query));
        List<AccountEntity> list = accountMapper.findByAccount(query);
        pages.setResult(list);
        return pages;
    }

    @Override
    public AccountEntity findByUserId(String userId) {

        return accountMapper.findByUserId(userId);
    }
}
